﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace XHCTMS.VIEW
{
    public partial class Job : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                Session["jobId"] = null;
                GetView();

            }
            
        }

        /// <summary>
        /// 得到所有职位信息
        /// </summary>
     private void GetView()
      {
                XHCTMS.BLL.JobInfo job = new BLL.JobInfo();
                DataTable dt = new XHCTMS.BLL.JobInfo().View();
                this.Jobinfo.DataSource = dt;
                Jobinfo.DataBind();
      }

        /// <summary>
        /// 增加职位信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        if (string.IsNullOrEmpty(txtName.Value))
        {
            //Response.Write("<script type='text/javascript'>alert('请输入要添加的职位名称！');</script>");
            ScriptManager.RegisterStartupScript(this.btnAdd, this.GetType(), "fd", "alert('请输入要添加的职位名称！')", true);
        }
        else if (string.IsNullOrEmpty(txtDesc.Value))
        {
           //Response.Write("<script type='text/javascript'>alert('请输入要添加的职位描述！');</script>");
            ScriptManager.RegisterStartupScript(this.btnAdd, this.GetType(), "fd", "alert('请输入要添加的职位描述')", true);
        }
        else
        {
        XHCTMS.MODEL.JobInfo job = new MODEL.JobInfo();
        job.JobName = this.txtName.Value;
        job.JobDesc = this.txtDesc.Value;

        if (rbtnSure.Checked)
        {
            job.JobFlag = 1;

        }
        else
        {
            job.JobFlag = 0;
        }

        int result = new XHCTMS.BLL.JobInfo().Add(job);
        GetView();
        this.txtName.Value = this.txtDesc.Value = null;
    }

}

        /// <summary>
        /// 查询职位信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSeach_Click(object sender, EventArgs e)
        {
            XHCTMS.MODEL.JobInfo job = new MODEL.JobInfo();
            if (!string.IsNullOrEmpty(txtName.Value))
            {
                job.JobName = txtName.Value;
            }
            if (!string.IsNullOrEmpty(txtDesc.Value))
            {
                job.JobDesc = txtDesc.Value;
            }
            if (!string.IsNullOrEmpty(rbtnSure.Text))
            {
                job.JobFlag = 0;
            }
            else
            {
                job.JobFlag =1;
            }

           // DataTable dt=
            this.Jobinfo.DataSource = new XHCTMS.BLL.JobInfo().SelecteBy(job);
            this.Jobinfo.DataBind();
            
            
        }

        /// <summary>
        /// 修改职位信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAlter_Click(object sender, EventArgs e)
        {
            int jobId = Convert.ToInt32(Session["jobId"]);
            MODEL.JobInfo job = new MODEL.JobInfo();
            job.JobName = this.txtName.Value;
            job.JobDesc = this.txtDesc.Value;
            int result = new BLL.JobInfo().Update(job);
            GetView();
            this.txtName.Value = this.txtDesc.Value = null;
        }

        /// <summary>
        /// 更新职位信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            GetView();
        }

        /// <summary>
        /// 删除职位信息
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {

        }

        protected void jobinfo_itemCommand(object source, RepeaterCommandEventArgs e)
        {

            int jobId = Convert.ToInt32(e.CommandArgument.ToString());
            Session["jobId"] = jobId;
            switch (e.CommandName)
            {
                case "linkbtnAlter":
                    MODEL.JobInfo job = new MODEL.JobInfo();
                    job.JobId = jobId;
                    DataTable dt = new BLL.JobInfo().ById(job);
                    this.txtName.Value = dt.Rows[0][1].ToString();
                    this.txtDesc.Value = dt.Rows[0][2].ToString();
                    break;
                case "linkbtnDelete":
                    int result = new BLL.JobInfo().AlterFlag(jobId);
                    GetView();
                    break;
            }
        }
    }
}